<?php
$pw = $_POST['pw'];
$ul = $_POST['ul'];
if ($pw == "" || $ul == "") {
    $a['error'] = 0;
    echo Json_encode($a);
    exit;
}
include_once "conn.php";
$sql = "select * from userinfo where username = '$ul' and pw = '" . md5($pw) . "'";
$result = mysqli_query($conn, $sql);
$num = mysqli_num_rows($result);
if ($num) {
    $info = mysqli_fetch_array($result);
    $sql = "insert into sss(userid,sj) VALUE ('" . $info['id'] . "','" . time() . "')";
    $result = mysqli_query($conn, $sql);
    if ($info['admin'] == 1) { //说明当前登录者是管理员
        $a['error'] = 2;
        echo Json_encode($a);

    }
    else {
        $a['error'] = 1;
        echo Json_encode($a);
    }
    $_SESSION['loggedUsername'] = $ul;
}
else {
    $a['error'] = 0;
    echo Json_encode($a);
}